$(
	function(){

	    fffCommerce.api.Products.getItem = function(productId,callback){
		
		var newProduct = {
		    uid:productId,
		    name:'Product A("test")' ,
		    shortName:"Prod A",
		    price:10.0,
		    description:"Suspendisse sollicitudin, dui nec elementum pharetra, nunc nibh tempor ante, a dapibus magna tellus at augue. Curabitur ullamcorper sem aliquet est volutpat mattis. Sed tincidunt leo semper sapien rhoncus porttitor. Nunc sapien augue, egestas ac pulvinar et",
		    thumbnail:"http://duckduckgo.com/sduck.v104.png"
		};

		callback(newProduct);
	    };

	    $("body").bind(
		fffCommerce.events.SHOW_DETAILS,
		function(event,productId){
		    new fffCommerce.Details().displayDetails(productId);
		});
	    	    
	    //alert(typeof myCart);	
	}
);

fffCommerce = fffCommerce || {};
fffCommerce.Details = function(){};

fffCommerce.Details.prototype = {
	
	sortPhotos:function(photos){
	    return photos.sort(
		function(photo1, photo2){
		    return photo1.priority < photo2.priority ? 
			-1 :
			photo1.priority > photo2.priority ?  1 : 0
		});
	},
	
	displayDetails: function(productId){
		
	    var _self = this;
	    fffCommerce.api.Products.getItem(productId, function(data){
		_self.fillDetailsPlaceholder(data);
	    })
		
	},
	
	fillDetailsPlaceholder: function(product){
	    
	    $.get(
		"./details.html",
		function(data){
		    
		    $('#details').html(data);
		    $("#image").attr("src", product.thumbnail);
		    $("#shortName").text(product.shortName);
		    $("#longName").text(product.name);
		    $("#description").text(product.description);
		    $("#price").text(product.price);
		    
		    $("#btnAddToCart").click(function(){
			new Cart().addProd(
			    {
				price:product.price,
				product_id:product.uid,
				short_name:product.shortName,
				qty:1
			    })
		    });
		    $("#prevImage").click(function(){
			$("#image").attr("src", product.thumbnail);
		    });
		    $("#nextImage").click(function(){
			$("#image").attr("src", product.thumbnail);
		    });
		});
	}
};
fffCommerce.Details.prototype.contructor = fffCommerce.Details;